package com.iqiyi.pps.epg.api.utils;

import com.alibaba.fastjson.JSONObject;

/**
 * Created by karkarrotxu on 2015/5/6.
 */
public final class RegUtil {
    public static final String REG_POSITIVE_INTEGER = "[1-9]\\d*";
    public static final String REG_SIMPLE_DATEFORMAT = "(19|20)\\d{2}-(0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-9]|3[0-1]) ([0-2][0-9]):([0-5][0-9]):([0-5][0-9])";
    public static final String REG_SHORT_SIMPLE_DATEFORMAT = "(19|20)\\d{2}-(0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-9]|3[0-1])";
    public static final String REG_CHECK_PLATFORM = "((1[0-9]|[1-9]|2[0-2]),)*(1[0-9]|[1-9]|2[0-2])";
    public static final String REG_PROGRAM_QIPU_ID = "[1-9]\\d*23";
    public static final String REG_CHANNEL_QUPUID = "[1-9]\\d*22";
    public static final String REG_NON_NEGATIVE_INTEGER = "\\d+";
    public static final String REG_INTEGER="\\-?\\d+";

    private static final String REG_TAG = "(\\d+_\\d+,)*\\d+_\\d+";
    private static final String REG_DOCNO = "ZB-\\d{14}";
    public static boolean isInteger(String checkValue) {
        if (checkValue == null) {
            return false;
        }
        return checkValue.matches(REG_INTEGER);
    }
    public static boolean isPositiveInteger(String checkValue) {
        if (checkValue == null) {
            return false;
        }
        return checkValue.matches(REG_POSITIVE_INTEGER);
    }

    public static boolean isNonnegativeInteger(String checkValue) {
        if (checkValue == null) {
            return false;
        }
        return checkValue.matches(REG_NON_NEGATIVE_INTEGER);
    }


    public static boolean isDateFormat(String checkValue) {
        if (checkValue == null) {
            return false;
        }
        return checkValue.matches(REG_SIMPLE_DATEFORMAT);
    }

    public static boolean isShortDateFormat(String checkValue) {
        if (checkValue == null) {
            return false;
        }
        return checkValue.matches(REG_SHORT_SIMPLE_DATEFORMAT);
    }

    public static boolean checkPlatform(String checkValue){
        if (checkValue == null) {
            return false;
        }
        return checkValue.matches(REG_CHECK_PLATFORM);
    }

    public static boolean checkProgramQipuId(String checkValue ){
        if (checkValue == null) {
            return false;
        }
        return checkValue.matches(REG_PROGRAM_QIPU_ID);
    }

    public static  boolean checkChannelQipuId(String checkValue){
        if (checkValue == null ) {
            return false;
        }
        return checkValue.matches(REG_CHANNEL_QUPUID);
    }
    public static  boolean checkTagValid(String checkValue){
        if (checkValue == null ) {
            return false;
        }
        return checkValue.matches(REG_TAG);
    }

    public static boolean  regCheck(String regex,String checkValue ){
        if (checkValue == null) {
            return false;
        }
        return checkValue.matches(regex);
    }

    public static boolean isJsonString(String str) {
        try {
            JSONObject jsonObject = JSONObject.parseObject(str);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    public static boolean isDocNo(String checkValue){
        if (checkValue == null ) {
            return false;
        }
        return checkValue.matches(REG_DOCNO);
    }
//
//    public static void main(String[] args){
//        System.out.println(isDocNo("ZB-43434111111111"));
//        System.out.println(isDocNo("ZB-4343411111111"));
//        System.out.println(isDocNo("ZB-43434www"));
//        System.out.println(isDocNo("dddZB-43434"));
//        System.out.println(isDocNo("dddZB\\-43434"));
//    }

}